const express = require('express');
const { routeWrapper } = require('../../../lib/module/tool/route');
const router = express.Router();

const orderService = require('../../../lib/service/orderService');

// 订单结算
router.post('/:areaId/orderSettlement', routeWrapper(async (req) => {
    const body = req.body;
    return orderService.orderSettlement(
        req.auth.userId,
        req.params.areaId,
        body.cartItemIdList,
        body.envelopeId,
        body.coinCount);
}, true));
// 提交订单
router.post('/:areaId/submitOrder', routeWrapper(async (req) => {
    const body = req.body;
    return orderService.submitOrder(
        req.auth.userId,
        req.params.areaId,
        body.addressInfo,
        body.cartItemIdList,
        body.remark,
        body.envelopeId,
        body.coinCount,
        body.paymentMode);
}, true));
// 校验订单支付状态
router.post('/:orderId/checkOrderPaymentStatus', routeWrapper(async (req) => {
    return orderService.checkOrderPaymentStatus(req.params.orderId);
}, true));

// 取消订单
router.post('/:orderId/cancelOrder', routeWrapper(async (req) => {
    return orderService.cancelOrder(req.auth.userId, req.params.orderId);
}, true));

// 订单退款
router.post('/:orderId/refund', routeWrapper(async (req) => {
    return orderService.refundOrder(req.auth.userId, req.params.orderId, req.body.price, req.body.refundDescribe);
}, true));

// 订单中心付款提交获取支付参数
router.get('/:orderId/pay_params', routeWrapper(async (req) => {
    return orderService.orderCenterPayment(req.auth.userId, req.params.orderId);
}, true));
module.exports = router;
